// Copyright (c) Microsoft Corporation.  All rights reserved.

#include "stdafx.h"
#include "D3D10ShaderReflection1.h"
#include "D3D10ShaderReflectionVariable.h"

using namespace Microsoft::WindowsAPICodePack::DirectX::Direct3D10;
using namespace msclr::interop;

UInt32 ShaderReflection1::BitwiseInstructionCount::get()
{
    UINT tempoutCount;
    CommonUtils::VerifyResult(GetInterface<ID3D10ShaderReflection1>()->GetBitwiseInstructionCount(&tempoutCount));
    return safe_cast<UInt32>(tempoutCount);
}

UInt32 ShaderReflection1::ConversionInstructionCount::get()
{
    UINT tempoutCount;
    CommonUtils::VerifyResult(GetInterface<ID3D10ShaderReflection1>()->GetConversionInstructionCount(&tempoutCount));
    return safe_cast<UInt32>(tempoutCount);
}

Primitive ShaderReflection1::GSInputPrimitive::get()
{
    D3D10_PRIMITIVE tempoutPrim;
    CommonUtils::VerifyResult(GetInterface<ID3D10ShaderReflection1>()->GetGSInputPrimitive(&tempoutPrim));
    return safe_cast<Primitive>(tempoutPrim);
}

UInt32 ShaderReflection1::MovcInstructionCount::get()
{
    UINT tempoutCount;
    CommonUtils::VerifyResult(GetInterface<ID3D10ShaderReflection1>()->GetMovcInstructionCount(&tempoutCount));
    return safe_cast<UInt32>(tempoutCount);
}

UInt32 ShaderReflection1::MovInstructionCount::get()
{
    UINT tempoutCount;
    CommonUtils::VerifyResult(GetInterface<ID3D10ShaderReflection1>()->GetMovInstructionCount(&tempoutCount));
    return safe_cast<UInt32>(tempoutCount);
}

ShaderInputBindDescription^ ShaderReflection1::GetResourceBindingDescriptionByName(String^ name)
{
    marshal_context^ context = gcnew marshal_context();
    ShaderInputBindDescription^ desc = gcnew ShaderInputBindDescription();
    CommonUtils::VerifyResult(GetInterface<ID3D10ShaderReflection1>()->GetResourceBindingDescByName(context->marshal_as<const char*>(name), desc->nativeObject.Get()));
    return desc;
}

ShaderReflectionVariable^ ShaderReflection1::GetVariableByName(String^ name)
{
    marshal_context^ context = gcnew marshal_context();
    ID3D10ShaderReflectionVariable* returnValue = GetInterface<ID3D10ShaderReflection1>()->GetVariableByName(context->marshal_as<const char*>(name));
    return returnValue == NULL ? nullptr : gcnew ShaderReflectionVariable(returnValue);
}

Boolean ShaderReflection1::IsLevel9Shader::get()
{
    BOOL tempoutbLevel9Shader;
    CommonUtils::VerifyResult(GetInterface<ID3D10ShaderReflection1>()->IsLevel9Shader(&tempoutbLevel9Shader));
    return tempoutbLevel9Shader != 0;
}

Boolean ShaderReflection1::IsSampleFrequencyShader::get()
{
    BOOL tempoutbSampleFrequency;
    CommonUtils::VerifyResult(GetInterface<ID3D10ShaderReflection1>()->IsSampleFrequencyShader(&tempoutbSampleFrequency));
    return tempoutbSampleFrequency != 0;
}

